'use strict';
exports.main = async (event, context) => {
	const db = uniCloud.database()
	const {
		mzId,
		userId,
		favoriteNum,
		date
	} = event
	if(!userId){
		return {
			code: -1,
			msg: "请先登录"
		}
	}
	try {
		const collection = db.collection('db_favorite_meizi')
		const res = await collection.add({
			mz_id: mzId,
			user_id: userId,
			date
		})
		const collection1 = db.collection('db_meizitu')
		const res1 = await collection1.doc(mzId).update({
			favoriteNum: favoriteNum + 1
		})

		return {
			code: 0,
			msg: "操作成功"
		}
	} catch (e) {
		return {
			code: -1,
			msg: "服务器错误"
		}
	}
};
